package com.scs.application.modules.device.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import com.scs.application.core.mvc.controller.CrudController;
import com.scs.application.core.query.QueryContext;
import com.scs.application.core.query.QueryContextHolder;
import com.scs.application.modules.device.entity.DeviceLedger;
import com.scs.application.modules.device.mapper.DeviceLedgerMapper;
import com.scs.application.modules.device.service.DeviceLedgerService;
import com.scs.application.modules.sys.model.PageResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 *  设备台账服务层
 */
@RestController
@RequestMapping("/device/ledger")
public class DeviceLedgerController extends CrudController<DeviceLedgerService, DeviceLedger>{

    @Resource
    private DeviceLedgerMapper deviceLedgerMapper;
    /**
     * 列表查询，选择使用
     */
    @GetMapping("/pageSelect")
    public PageResult pageSelect(@RequestParam Map<String, Object> reqData) {
        Map<String, Object> userParam = null;
        //固定参数
        if (reqData.containsKey("userParam")) {
            JSONObject ob = JSON.parseObject(reqData.get("userParam") + "");
            userParam = Maps.newHashMap(ob);
        }

        QueryContext context = QueryContextHolder.currentContext();
        IPage pageResult = deviceLedgerMapper.pageSelect(context.getPage(), context.getWrapper(), userParam);
        return PageResult.ok("查询成功", pageResult.getRecords(), pageResult.getTotal());
    }
}